<?php
namespace app\admin\model;

use think\Model;

class Users extends Base
{
    protected $name = 'users';
    protected $createTime = false;
    protected $updateTime = false;

    // 获取用户列表
    public function getUserList($where = [], $curr = 1, $limit = 20, $field = '*'){
        $page = ($curr - 1) * $limit;
        $list = $this->where($where)->field($field)->limit($page, $limit)->select();

        if($list->isEmpty()){
            return ['code' => 'fail'];
        }

        foreach($list as $k => $v){
            $field = 'money, point, star_id, status, create_time, star_time';
            $userShop = (new UserShop())->getFind(['user_id' => $v['id'], 'admin_id' => $v['bind_admin_id']], $field)['data'];

            $v['money']       = $userShop['money'];
            $v['point']       = $userShop['point'];
            $v['star_id']     = $userShop['star_id'];
            $v['status']      = $userShop['status'];
            $v['star_time']   = $userShop['star_time'];
            $v['create_time'] = $userShop['create_time'];
        }

        return ['code' => 'ok', 'list' => $list];
    }

    public function getAdminIdAttr($val){
        if(!$val){
            return '-';
        }

        return (new Admin())->getFind(['id' => $val])['data'];
    }
}